#include "stdafx.h"
#include "ReadsMappingStats.h"

CReadsMappingStats::CReadsMappingStats(void)
{
    this->initialization();
}

CReadsMappingStats::~CReadsMappingStats(void)
{

}

void CReadsMappingStats::initialization(void)
{
    this->iReadsFileCount = 0;
    this->initializeStatsCounter(); // Counters
}

void CReadsMappingStats::initializeStatsCounter(void)
{
    this->iBadReadCounter = 0;
    this->iMapCount = 0;
    this->iReadCounter = 0;
    this->iMissReadCounter = 0;
    this->iMultiMappedReads = 0;
    this->iReadsFileCount = 0;

    for (unsigned int i = 0; i <= MAXTOLERATSUBMIS; i++) {
        // Temporarily assume there have same # of record
        this->iMapDiffCount[i] = 0;
    }
}

int CReadsMappingStats::printMappingStats(ostream& out, const char* readSetName,\
        unsigned int uiSubThreshold) const
{
    unsigned int i;
    out << endl;
    out << readSetName << ", Reads:, ";
    out << "Filtered#, " << iBadReadCounter << ", ";
    out << "Kept#, " << iReadCounter << ", ";
    out << "Mapped#, " << iMapCount << ", ";
    out << "Multi-mapped#, " << iMultiMappedReads << BLANK_LINE << endl;
    if (hasTheExtName(readSetName, ".fa") || \
            hasTheExtName(readSetName, ".fasta") || \
            hasTheExtName(readSetName, ".fna")) {
        out << readSetName << ",_ ";
        for (i = 0; i <= uiSubThreshold; i++) {
            out << "Sub" << i << ", " << iMapDiffCount[i] << ", " ;
        }
        out << endl;
    }
    return(0);
}

// return true if print the alignments
bool CReadsMappingStats::bookKeepMapping(CAlignmentsQ& que, bool bExcludeAmbiguous)
{
    this->iMapCount++;
    this->iMapDiffCount[que.MinDiff]++;
    if (que.AmbiguousFlag) {
        this->iMultiMappedReads++;
        if (bExcludeAmbiguous) {
            return(false);
        }
    }
    return(true);
}

